package com.flykoc.lightinggem.dto;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 闪电宝石对象模型
 *
 * @author Zoyn
 * @since 2017-10-21
 */
public class LightingGem {

    private int material;
    private int data;
    private double damage;
    private String name;
    private int level;
    private List<String> description;
    private double odds;

    /**
     * @param material    物品id
     * @param data        物品子id
     * @param damage      造成的闪电伤害
     * @param name        展示名
     * @param level       等级
     * @param description lore
     * @param odds        触发
     */
    public LightingGem(int material, int data, double damage, String name, int level, List<String> description, double odds) {
        this.material = material;
        this.data = data;
        this.damage = damage;
        this.name = name;
        this.level = level;
        this.description = description;
        this.odds = odds;
    }

    public int getMaterial() {
        return material;
    }

    public void setMaterial(int material) {
        this.material = material;
    }

    public int getData() {
        return data;
    }

    public void setData(int data) {
        this.data = data;
    }

    public double getDamage() {
        return damage;
    }

    public void setDamage(double damage) {
        this.damage = damage;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public List<String> getDescription() {
        return description;
    }

    public void setDescription(List<String> description) {
        this.description = description;
    }

    public double getOdds() {
        return odds;
    }

    public void setOdds(double odds) {
        this.odds = odds;
    }

    @SuppressWarnings({"deprecation"})
    public ItemStack getItemStack() {
        ItemStack itemStack = new ItemStack(Material.getMaterial(material), 1, (short) data);
        if (name == null) {
            return itemStack;
        }
        ItemMeta itemMeta = itemStack.getItemMeta();
        itemMeta.setDisplayName(name);

        if (description != null) {
            if (!description.isEmpty()) {
                // 替换description里的颜色代码
                List<String> temp = description.stream()
                        .map(s -> ChatColor.translateAlternateColorCodes('&', s))
                        .collect(Collectors.toList());

                itemMeta.setLore(temp);
            }
        }

        itemStack.setItemMeta(itemMeta);
        return itemStack;
    }

    @Override
    public String toString() {
        return "LightingGem{" +
                "material=" + material +
                ", data=" + data +
                ", damage=" + damage +
                ", name='" + name + '\'' +
                ", level=" + level +
                ", description=" + description +
                ", odds=" + odds +
                '}';
    }
}
